package com.jit.monitor.presenter;

import android.annotation.SuppressLint;

import com.jit.baselib.bean.response.BaseListResponse;
import com.jit.baselib.ui.base.BaseActivity;
import com.jit.baselib.ui.base.BaseObserver;
import com.jit.baselib.ui.base.BasePresenter;
import com.jit.baselib.ui.base.ExceptionHandle;
import com.jit.monitor.base.ApiRetrofit;
import com.jit.monitor.commom.AppConstant;
import com.jit.monitor.model.response.CtFrameResponse;
import com.jit.monitor.view.CtFrameAtView;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * @author crazyZhangxl on 2018/12/21.
 * Describe:
 */
public class CtFrameAtPresenter extends BasePresenter<CtFrameAtView>{

    public CtFrameAtPresenter(BaseActivity context) {
        super(context);
    }

    @SuppressLint("CheckResult")
    public void queryCtFrameList(String frameID, String obj){
        getView().showLoadingDialog();
        ApiRetrofit.getInstance().getCurrentDetailDetInfo(frameID,obj)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseListResponse<CtFrameResponse>>() {
                    @Override
                    public void onNext(BaseListResponse<CtFrameResponse> ctFrameResponseBaseListResponse) {
                        CtFrameAtPresenter.this.getView().hideLoadingDialog();
                        if (ctFrameResponseBaseListResponse.getCode() == AppConstant.REQUEST_SUCCESS) {
                            CtFrameAtPresenter.this.getView().queryCtFrameSuccess(ctFrameResponseBaseListResponse.getData());
                        } else {
                            CtFrameAtPresenter.this.getView().queryFrameFailure(ctFrameResponseBaseListResponse.getMsg());
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseException exception) {
                        CtFrameAtPresenter.this.getView().hideLoadingDialog();
                        CtFrameAtPresenter.this.getView().queryFrameFailure(exception.getLocalizedMessage());
                    }
                });

    }

}
